//
//  CMDBUserCenterPhotoLibraryViewController.swift
//  CMDB
//
//  Created by 曹桂祥 on 2017/5/22.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

private let kPhotLibraryCellID = "kPhotLibraryCellID"

class CMDBUserCenterPhotoLibraryViewController: CMDBUserBaseCenterViewController {
    
    var albumModels : [CMDBAlbumsBean] = [CMDBAlbumsBean]()
    
    lazy var libraryCollectionView : BaseCollectionView = {
    
        let layout                     = UICollectionViewFlowLayout()
        
        layout.itemSize                = CGSize(width: 300 * CMDB_Rate, height: 380 * CMDB_Rate)
        
        layout.minimumLineSpacing      = 10
        
        layout.minimumInteritemSpacing = 10
        
        layout.sectionInset            = UIEdgeInsets(top: KleftMargin, left: 25, bottom: KleftMargin, right: 25)
        
        layout.scrollDirection         = .Vertical
        
        let libraryCollectionView                            = BaseCollectionView(frame: CGRect.zero, collectionViewLayout: layout)
        
        libraryCollectionView.showsHorizontalScrollIndicator = false
        
        libraryCollectionView.showsVerticalScrollIndicator   = false
        
        libraryCollectionView.bounces                        = false
        
        libraryCollectionView.clipsToBounds                  = false
        
        libraryCollectionView.delegate                       = self
        
        libraryCollectionView.dataSource                     = self
        
        libraryCollectionView.backgroundColor                = UIColor.whiteColor()
        
        libraryCollectionView.registerClass(CMDBUserCenterPhotoLibraryCell.self, forCellWithReuseIdentifier: kPhotLibraryCellID)
        
        return libraryCollectionView
    
    }()

    override func setup() {
        super.setup()
        
        buidCollectionView()
        
        requestData()
    }
    
}

extension CMDBUserCenterPhotoLibraryViewController{
    
    func buidCollectionView(){
        
        view.addSubview(libraryCollectionView)
        
        let contentH = CMDB_Screen_Height - KNavBarHeight - CMDB_Screen_Width * 0.5
        
        libraryCollectionView.frame = CGRect(x: 0, y: 0, width: CMDB_Screen_Width, height: contentH)
        
        
    }
}

extension CMDBUserCenterPhotoLibraryViewController{
    
    func requestData(){
        
        let timeStr = "更新于12月28日"
        
        let nameStrArr = ["旅游相册","头像相册","剧组相册","个人相册"]
        
        nameStrArr.map ({
            albumModels.append(CMDBAlbumsBean(name: $0, cover: "相册背景图", lastTime: timeStr))
        })
        
    }
    
}

//MARK:- collectionViewDataSource
extension CMDBUserCenterPhotoLibraryViewController : UICollectionViewDelegate{
    
    
}

//MARK:- collectionViewDelegate
extension CMDBUserCenterPhotoLibraryViewController : UICollectionViewDataSource{

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return albumModels.count ?? 0
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(kPhotLibraryCellID, forIndexPath: indexPath) as! CMDBUserCenterPhotoLibraryCell
        
        cell.libraryBean = albumModels[indexPath.item]
        
        return cell
        
    }
    
}